import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../generated/l10n.dart';
import '../pages/Calendar.dart';
import '../pages/GamePage.dart';
import '../utils/AudioUtils.dart';
import '../utils/CommUtils.dart';
import '../utils/GamePageUtils.dart';
import '../utils/HelpUtils.dart';
import '../utils/TimeUtils.dart';
import '../routers/router.dart';

const Color textbgColor = Color.fromARGB(156, 237, 229, 12);

const Color textColor = Colors.white;
const colorList = [
  Color(0xffffffff),
  Color(0Xff5afddd),
];
//每个月宝石情况
const evearyGem = [
  "assets/images/gem1.png",
  "assets/images/gem2.png",
  "assets/images/gem3.png",
  "assets/images/gem4.png",
  "assets/images/gem5.png",
  "assets/images/gem6.png",
  "assets/images/gem7.png",
  "assets/images/gem8.png",
  "assets/images/gem9.png",
  "assets/images/gem10.png",
  "assets/images/gem11.png",
  "assets/images/gem12.png",
];

//我的
// ignore: must_be_immutable
class My extends StatefulWidget {
  Widget setingWight;

  My({
    Key? key,
    required this.setingWight,
  }) : super(key: key);

  @override
  State<My> createState() => _MyState();
}

class _MyState extends State<My> {
  @override
  Widget build(BuildContext context) {
    double size = CommUtils.getWidth(context);
    double hight = CommUtils.getHeight(context);
    return Stack(
      children: [
        Align(
          alignment: Alignment.center,
          child: Wrap(
            children: [
              Column(
                children: [
                  SizedBox(
                    height: hight * 0.25,
                  ),
                  Padding(
                    padding: EdgeInsets.only(
                      left: size*0.05,
                      right: size*0.05,
                      bottom: hight*0.03,
                    ),
                    child: Container(
                      width: double.infinity,
                      decoration: BoxDecoration(
                        image: DecorationImage(
                            image: AssetImage('assets/images/middle.png'),
                            fit: BoxFit.fill),
                      ),
                      child: Padding(
                        padding: EdgeInsets.all(size*0.03),
                        child: Column(
                          children: [
                            Stack(
                              children: [
                                Align(
                                  alignment: Alignment.centerLeft,
                                  child: GestureDetector(
                                    onTap: () {
                                      //日历
                                      AudioUtils.getInstance()
                                          ?.play2("start_game.mp3");
                                      HelpUtils().navigatorToTargetPage(
                                          context, Calendar(),
                                          callBack: ((selectIndex) {
                                        if (selectIndex == 1) {
                                          setState(() {});
                                        }
                                      }));
                                    },
                                    child: Image.asset(
                                        'assets/images/calendar.png',
                                         width:  hight*0.04,
                                        fit: BoxFit.contain),
                                  ),
                                ),

                                Align(
                                  alignment: Alignment.center,
                                  child: Container(
                                    margin: EdgeInsets.only(
                                      left: hight * 0.1, ),
                                 
                                    child: Row(
                                      mainAxisSize: MainAxisSize.min,
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: [
                                        Image.asset('assets/images/crown.png',
                                            width:  hight*0.04,
                                            fit: BoxFit.contain),
                                        //每日的挑战 maxFontSize: 16 显示长度，以免被超过屏幕
                                        Align(
                                          alignment: Alignment.bottomCenter,
                                            child: CommUtils.getText(context, 18,
                                             S.current.daily_challenges,maxFontSize: 16),                                       
                                        ),

                                        SizedBox(
                                          width: size * 0.1,
                                        )
                                      ],
                                    ),
                                  ),
                                ),

                                // Image.asset('assets/images/diamond.png',
                                //     width: ScreenUtil().setHeight(40),
                                //     height: ScreenUtil().setHeight(33),
                                //     fit: BoxFit.cover),
                              ],
                            ),
                            GamePageUtils().challengeComplete(false)
                                ? HelpUtils().getcomplete(context)
                                : Column(children: [
                                    SizedBox(
                                      height: hight*0.02,
                                    ),
                                    AutoSizeText(
                                      TimeUtils.gtTime2(DateTime.now()),
                                      style: TextStyle(
                                        fontSize: ScreenUtil().setSp(13),
                                        fontWeight: FontWeight.bold,
                                        color: Color.fromRGBO(255, 255, 255, 1),
                                        height: 0.7,
                                      ),
                                      maxLines: 2,
                                      textAlign: TextAlign.center,
                                      overflow: TextOverflow.ellipsis,
                                    ),
                                    SizedBox(
                                      height: hight*0.02,
                                    ),
                                    // 开始游戏
                                    HelpUtils().getnewGame(context,
                                        callBack: ((selectIndex) {
                                      //  print("我的界面挑战成功了回调了");
                                      if (selectIndex == 1) {
                                        setState(() {});
                                      }
                                    })),
                                  ]),
                          ],
                        ),
                      ),
                    ),
                  ),
                  SizedBox(
                    height: hight * 0.056,
                  ),
                  //新游戏
                  GestureDetector(
                    onTap: () {
                      _playAudio("start_game.mp3");
                      AudioUtils.getInstance()?.stopHomeBGm();
                      startPageDown2(
                        context,
                        GamePage(
                          isContinue: false,
                        ),
                        calllBack: (selectIndex) => setState(() {}),
                      );
                    },
                 
                      child: Container(
                          height: hight*0.05,
                          width: hight*0.35,
                          decoration: BoxDecoration(
                            image: DecorationImage(
                              image: AssetImage('assets/images/new_game.png'),
                              fit: BoxFit.fill,
                            ),
                          ),
                          alignment: Alignment.center,
                          child: CommUtils.getTextGame(
                            context,
                            15,
                            S.current.new_game,
                            // Color(0xffe7f9c6),
                            colorList[0],
                            colorList[1],
                          )),
                    
                  ), //新游戏
                ],
              ),
            ],
          ),
        ),

        Align(
          alignment: Alignment.topCenter,
          child: Image.asset('assets/images/logo.png',
              width:hight*0.3,
              height: hight*0.3,
              fit: BoxFit.fitWidth), //logo),
        ),
        //设置
        Padding(
          padding: EdgeInsets.only(
              left: 0,
              top: hight * 0.05,
              right: size * 0.05,
              bottom: 0),
          child: Container(
            height:hight * 0.05,
            child: Stack(children: [
              widget.setingWight,
            ]),
          ),
        ),
      ],
    );
  }

  /**
 * 播放音乐
 */
  void _playAudio(String path) {
    AudioUtils.getInstance()?.play2(path);
  }
}
